
import 'dart:convert';
import 'package:ichinesereader/models/common/Settings.dart';

LoginResult loginResponseFromJson(String str) =>
    LoginResult.fromJson(json.decode(str));

String loginResponseToJson(LoginResult data) => json.encode(data.toJson());

class LoginResult {
  LoginResult({
    this.authToken,
    this.code,
    this.message,
    this.roles,
    this.user,
  });

  String? authToken;
  String? code;
  String? message;
  List<String>? roles;
  User? user;

  factory LoginResult.fromJson(Map<String, dynamic> json) => LoginResult(
        authToken: json["authToken"],
        code: json["code"],
        message: json["message"],
        roles: json["roles"] != null
            ? List<String>.from(json["roles"].map((x) => x))
            : null,
        user: json["user"] != null ? User.fromJson(json["user"]) : null,
      );

  Map<String, dynamic> toJson() => {
        "authToken": authToken,
        "code": code,
        "message": message,
        "roles": roles != null
            ? List<String>.from(roles!.map((x) => x))
            : null, //不能为null
        "user": user != null ? user?.toJson() : null,
      };
}

class User {
  bool? deleted;
  bool? disabled;
  String? email;
  String? firstName;
  String? lastLogIn;
  int? lastLoggedIn;
  String? lastName;
  String? profileImageUrl;
  List<String>? role;
  Settings? settings;
  int? timestampCreated;
  int? timestampDisabled;
  int? timestampEnabled;
  int? timestampPasswordChanged;
  String? userId;
  String? userName;

  User(
      {this.deleted,
      this.disabled,
      this.email,
      this.firstName,
      this.lastLogIn,
      this.lastLoggedIn,
      this.lastName,
      this.profileImageUrl,
      this.role,
      this.settings,
      this.timestampCreated,
      this.timestampDisabled,
      this.timestampEnabled,
      this.timestampPasswordChanged,
      this.userId,
      this.userName});

  User.fromJson(Map<String, dynamic> json) {
    deleted = json['deleted'];
    disabled = json['disabled'];
    email = json['email'];
    firstName = json['firstName'];
    lastLogIn = json['lastLogIn'];
    lastLoggedIn = json['lastLoggedIn'];
    lastName = json['lastName'];
    profileImageUrl = json['profileImageUrl'];
    role = json['role'].cast<String>();
    settings = json['settings'] != null
        ? new Settings.fromJson(json['settings'])
        : null;
    timestampCreated = json['timestampCreated'];
    timestampDisabled = json['timestampDisabled'];
    timestampEnabled = json['timestampEnabled'];
    timestampPasswordChanged = json['timestampPasswordChanged'];
    userId = json['userId'];
    userName = json['userName'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['deleted'] = this.deleted;
    data['disabled'] = this.disabled;
    data['email'] = this.email;
    data['firstName'] = this.firstName;
    data['lastLogIn'] = this.lastLogIn;
    data['lastLoggedIn'] = this.lastLoggedIn;
    data['lastName'] = this.lastName;
    data['profileImageUrl'] = this.profileImageUrl;
    data['role'] = this.role;
    if (this.settings != null) {
      data['settings'] = this.settings!.toJson();
    }
    data['timestampCreated'] = this.timestampCreated;
    data['timestampDisabled'] = this.timestampDisabled;
    data['timestampEnabled'] = this.timestampEnabled;
    data['timestampPasswordChanged'] = this.timestampPasswordChanged;
    data['userId'] = this.userId;
    data['userName'] = this.userName;
    return data;
  }
}
